package uk.co.drpj.rep;

import java.util.NavigableMap;
import java.util.TreeMap;

public class TreeMapSequence implements MapSequence {

	
	TreeMap<Double,Map> maps;
	double bit=1e-3; // in case we get rounding errors
	
	public TreeMapSequence() {
		super();
		this.maps = new TreeMap<Double,Map>();;
	}

	public Map getMapFor(double t) {
		NavigableMap<Double, Map> head = maps.headMap(t+bit, true);
		return head.lastEntry().getValue();
	}
	
	public Map getMapAt(double t) {
		 return maps.get(t);
	}

	
	public Map replaceMapAt(double t,Map map) {
		 Map tmp=maps.get(t);
		 maps.put(t, map);
		 return tmp;
	}

	public void put(double d, Map map) {
		maps.put(d, map);		
	}

}
